package User;

import Book.Book;
import Utils.ScannerSingleton;
import Book.Library;
import java.time.LocalDate;
import java.util.Scanner;

public class AdminUser extends User{
    public Scanner scanner;
    public Library library = Library.getLibrary();
    public AdminUser(String name, int userid) {
        super(name, userid, "管理员");
        this.library = Library.getLibrary();
    }

    @Override
    public int display() {
        scanner = ScannerSingleton.getScanner();
        System.out.println(" 管理员 " + name + " 的操作菜单:");
        System.out.println("1. 查找图书 ");
        System.out.println("2. 打印所有的图书 ");
        System.out.println("3. 退出系统 ");
        System.out.println("4. 上架图书 ");
        System.out.println("5. 修改图书 ");
        System.out.println("6. 下架图书 ");
        System.out.println("7. 统计借阅次数 ");
        System.out.println("8. 查看最后欢迎的前 K 本书 ");
        System.out.println("9. 查看库存状态 ");
        System.out.println("10. 检查超过⼀年未下架的图书 ");
        System.out.println(" 请选择你的操作： ");
        return scanner.nextInt();
    }
    //上架图书
    public void addBook() {
        scanner.nextLine();
        System.out.println(" 请输⼊书名： ");
        String title = scanner.nextLine();  //输⼊书名

        System.out.println(" 请输⼊作者： ");
        String author = scanner.nextLine();  //输⼊作者

        System.out.println(" 请输⼊类别： ");
        String category = scanner.nextLine();  //输⼊图书类别

        System.out.println(" 请输⼊出版年份： ");
        int year = scanner.nextInt();  //输⼊出版年份
        scanner.nextLine();
        LocalDate shelfDate = LocalDate.now();
        Book newBook = new Book(title, author, category, year, shelfDate);
        newBook.setBookId(library.getNextBookId());
        library.addBook(newBook);
    }
    //图书修改⽀持修改书名作者类别

    public void updateBook() {
        library.displaybook();
        System.out.println(" 请输入要修改的图书编号： ");
        int bookid = scanner.nextInt();
        scanner.nextLine();
        Book book = library.searchBook(bookid);
        if (book == null){
            System.out.println(" 图书不存在！ ");
        }
        System.out.println(" 请输入要修改的图书书名： ");
        String title = scanner.nextLine();
        book.setTitle(title);
        System.out.println(" 请输入要修改的图书作者： ");
        String author = scanner.nextLine();
        book.setAuthor(author);
        library.updatebook(book);

    }
    //删除书籍
    public void removeBook() {
        library.displaybook();
        System.out.println(" 请输入要删除的图书编号： ");
        int bookid = scanner.nextInt();
        scanner.nextLine();
        Book removebook = library.searchBook(bookid);
        if (removebook == null){
            System.out.println(" 图书不存在！ ");
        }
        library.removeBook(bookid);
    }
    //统计每本书的借阅次数
    public void borrowCount() {
        library.borrowcount();
    }
    //查询最受欢迎的前 K 本书
    public void generateBook() {
        System.out.println("请输入小于"+library.bookCount);
        int k = scanner.nextInt();
        if (k > library.bookCount || k <= 0){
            System.out.println("输入的K值不合法");
            return;
        }
        library.generateBook(k);
    }
    //查看库存状态
    public void checkInventoryStatus() {
        library.checkInventoryStatus();
    }
    //移除上架超过⼀年的图书
    public void checkAndRemoveOldBooks() {
        library.checkAndRemoveOldBooks();
    }
    public void exit() {
    }
}
